package com.hc.lifecycle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/6/9 15:09
 */
@Component
@Slf4j
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Nullable
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (Objects.equals(beanName, "initService")) {
            log.info("4、BeanPostProcessor.before: {}", beanName);
        }
        return bean;
    }

    @Nullable
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (Objects.equals(beanName, "initService")) {
            log.info("6、BeanPostProcessor.after: {}", beanName);
        }
        return bean;
    }
}
